<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.myfirefly.cn/tag/auth" prefix="auth"%>
<script type="text/javascript">
	var spfTradeWageDataGrid = $('#spfTradeWage-datagrid-json').datagrid({
		gridTitle : '工资情况管理',
	    showToolbar: true,
	    toolbarItem: '',
	    addLocation: 'first',
	    showLinenumber: false,
	    filterThead: false,
	    filterAll: true,
	    sortAll : true,
	    <auth:has funcId="spfTradeContractManage" action="/spfTradeContractManage/wagelist.do">
	    dataUrl: 'spfTradeContractManage/wagelist.do?contractId=${contractId}',
	    </auth:has>
	    dataType: 'json',
	    columns: [
	        {
				name: '',
				label: '操作',
				align: 'center',
				width: 140,
				quicksort:false,
				menu: false,
				edit: false,
				render: function(value){
			        var html = '';
			        <auth:has funcId="spfTradeContractManage" action="/spfTradeContractManage/editWage.do">
			    	html += '<div class="btn-group" role="group"><button type="button" class="btn btn-blue btn-sm" onclick="editSpfTradeWage(this)"><i class="fa fa-edit"></i> 编辑</button></div>';
			    	</auth:has>
			    	<auth:has funcId="spfTradeContractManage" action="/spfTradeContractManage/delWage.do">
			    	html += '<div class="btn-group" role="group"><button type="button" class="btn btn-red btn-sm" onclick="delSpfTradeWage(this)"><i class="fa fa-remove"></i> 删除</button></div>';
				    </auth:has>
			    	return html;
				}
	        },
	        
	        {
	            name: 'grantType',
	            label: '发放情况',
	            type : 'select',
	            items:[
	            	{'1':'已到账未网签'},
	            	{'2':'未到账已网签'},
	            	{'3':'已到账已网签'},
	            	{'4':'补网签'}
	            ],
	            align: 'center',
	            width: 120,
	            render: $.datagrid.renderItem,
	            quicksort:false,
				menu: false,
				edit: false,
	        },
	        {
	            name: 'wageDetail',
	            label: '发放详情',
	            align: 'center',
	            width: 500,
	            quicksort:false,
				menu: false,
				edit: false,
	        }

	    ],
	    afterSave: function($trs, datas) {
	        	this.refresh();
	        },
	    paging: {pageSize:20, selectPageSize:'20,30,40'},
	    showTfoot: true,
	    fullGrid: false,
	    toolbarCustom: function(){
	    	var html = '';
	    	<auth:has funcId="spfTradeContractManage" action="/spfTradeContractManage/addWage.do">
	    	html += '<div class="btn-group" role="group"><button type="button" class="btn btn-blue" onclick="addSpfTradeWage()"><i class="fa fa-plus"></i> 添加</button></div>';
	    	</auth:has>
	    	html += '<div class="btn-group" role="group"><button type="button" class="btn btn-green" onclick="refreshSpfTradeWage()"><i class="fa fa-refresh"></i> 刷新</button></div>';
		    return html;
	    }
	});
	try {
		spfTradeWageDataGrid.data('bjui.datagrid').colLock(0, true);
	} catch (e) { }
	
	function refreshSpfTradeWage() {
		spfTradeWageDataGrid.datagrid("refresh");
	}

	function addSpfTradeWage() {
		$('#edit-spfTradeWage-dialog').dialog({
			id:'add-spfTradeWage-dialog', 
			url:'spfTradeContractManage/addWage.do?contractId=${contractId}', 
			maxable: false,
			mask: true,
			width: 850,
			height: 300,
			onLoad: function($dialog){
				setEditSpfTradeWageBtnEvent($dialog, true);
			},
			title:'工资情况管理 - 添加'});
	}
	function editSpfTradeWage(_this) {
		var index = $(_this).closest("tr").index();
		var data = spfTradeWageDataGrid.data('bjui.datagrid').getRowData(index);
		$('#edit-spfTradeWage-dialog').dialog({
			id:'edit-spfTradeWage-dialog',
			url:'spfTradeContractManage/editWage.do',
			maxable: false,
			mask: true,
			width: 850,
			height: 300,
			onLoad: function($dialog){
				
				setEditSpfTradeWageBtnEvent($dialog, false);
				
				// 根据data中的loginName，取得数据并加载到form表单中
				getJsonData2Form('spfTradeContractManage/getWage.do', 'id='+data.id, $('#spfTradeWage_form'), spfTradeWageCallback);
				
			},
			
			title:'工资情况管理 - 编辑'});
	}
	function delSpfTradeWage(_btn){
		var index = $(_btn).closest("tr").index();
		var data = spfTradeWageDataGrid.data('bjui.datagrid').getRowData(index);

		spfTradeWageDataGrid.alertmsg('confirm', '确定删除当前数据？', 
			{
			    displayMode:'slide', 
	            okName:'确定', 
	            cancelName:'取消', 
	            title:'提示信息',
	            okCall : function(){
	            	var url = "spfTradeContractManage/delWage.do?id="+data.id;
					var successCallBack = function(){
						refreshSpfTradeWage();
					}
					myAjax(url,	null, null,successCallBack,null);
	            }
	    });
	}
	
	function spfTradeWageCallback($inputObj, _name, _val){
		
	}
	
	function setEditSpfTradeWageBtnEvent($dialog, isAdd) {
		var $save, $cancel;
		$save = $dialog.find('.save');
		$cancel = $dialog.find('.cancel');
	
		$save.click(function(){
			$('#spfTradeWage_form').isValid(function(v) {
				if(v){
					var url = 'spfTradeContractManage/addWageSave.do';
					if (!isAdd) {
						url = 'spfTradeContractManage/editWageSave.do';
					}
					var data = $('#spfTradeWage_form').serialize();
					var successCallBack = function(){
						$dialog.dialog('closeCurrent');
						refreshSpfTradeWage();
					}
					myAjax(url,	data, true,successCallBack,null);
				}
			});
		});
	
		$cancel.click(function(){
			if (isAdd) {
				$dialog.dialog('close', 'add-spfTradeWage-dialog');
			} else {
				$dialog.dialog('close', 'edit-spfTradeWage-dialog');
			}
		});
	}
</script>
<div class="bjui-pageContent" id="spfTradeWage-index-pagecontent">
    <div style="padding:0px; height:100%; width:100%;">
        <table id="spfTradeWage-datagrid-json" data-width="100%" data-height="100%" class="table table-bordered">
        </table>
    </div>
</div>
<div id="edit-spfTradeWage-dialog" style="display: none;">
</div>
</div>